package com.codefish.codefishseckill.config;

import com.codefish.codefishseckill.config.interceptor.CommonWebFilter;
import com.codefish.codefishseckill.config.interceptor.ThreadLocalPageInfoFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;

/**
 * 描述
 *
 * @author codefish
 * @version 1.0
 * @date 2022/07/05 下午 05:46
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    HandlerInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(loginInterceptor).addPathPatterns("/goods/**")
//                .addPathPatterns("/seckill/**")
//                .excludePathPatterns("/seckill/testSeckill/*")
//                .excludePathPatterns("/goods/rest/goodsDetail");
    }


    @Bean
    FilterRegistrationBean<CommonWebFilter> commonWebFilterFilterRegistrationBean() {
        FilterRegistrationBean<CommonWebFilter> filterBean = new FilterRegistrationBean<>(new CommonWebFilter());
        filterBean.setUrlPatterns(Arrays.asList("/*"));
        return filterBean;
    }

    @Bean
    FilterRegistrationBean<ThreadLocalPageInfoFilter> threadLocalPageInfoFilterFilterRegistrationBean() {
        FilterRegistrationBean<ThreadLocalPageInfoFilter> filterBean = new FilterRegistrationBean<>(new ThreadLocalPageInfoFilter());
        filterBean.setUrlPatterns(Arrays.asList("/goods/toList","/goods/rest/toList"));
        return filterBean;
    }

}
